<template>
	<view :data-theme="themeStyle">
		<view class="head-box">
			<view class="part-one">
				<view class="team-all">总业绩（包含未结算与已退款）</view>
				<view class="team-num">{{total}}</view>
			</view>
			<view class="part-two">
				<view class="menu-item" :class="selectIndex == index ? 'native' : ''" v-for="(item,index) in menus"
					@click="selectEvent(index)">{{item.name}}
				</view>
			</view>
		</view>
		<mescroll-uni ref="mescroll" @getData="getData" :top="relationTop" class="member-point" :size="8">
			<view class="goods_list" slot="list">
				<view class="order-list">
					<view class="order-item" v-for="(orderItem, orderIndex) in orderList" :key="orderIndex">
						<block v-if="selectIndex == 0">
							<view class="item-type-one">
								<image class="img-box"
									:src="orderItem.headimg ? $util.img(orderItem.headimg) : $util.getDefaultImage().default_headimg">
								</image>
								<view class="c-box">
									<view class="c-o-box">
										<view class="name-label">{{orderItem.nickname}}</view>
										<view class="num-label">+{{orderItem.commission}}</view>
									</view>
									<view class="dec-label">订单号 {{orderItem.order_no}}</view>
									<view class="dec-label">时间 {{$util.timeStampTurnTime(orderItem.create_time)}}</view>
								</view>
							</view>
						</block>
						<block v-else>
							<view class="item-type-two">
								<view class="p-one-box">
									<view class="date-label">{{orderItem.order_date}}</view>
									<view class="num-label">+{{orderItem.commission}}</view>
								</view>
								<!-- <view class="time-box">2024-10-10 00:05:51至2024-10-11 00:05:51</view> -->
							</view>
						</block>
					</view>
				</view>
				<view class="cart-empty">
					<ns-empty text="暂无数据" :isIndex="!1" v-if="orderList.length == 0 && emptyShow"></ns-empty>
				</view>
			</view>
		</mescroll-uni>
		<ns-login ref="login"></ns-login>
		<loading-cover ref="loadingCover"></loading-cover>
	</view>
</template>

<script>
	import globalConfig from '@/common/js/golbalConfig.js';
	export default {
		data() {
			return {
				orderList: [],
				emptyShow: false,
				relationTop: 274,
				menus: [{
						name: '明细',
						type: 0
					},
					{
						name: '日统计',
						type: 1
					},
					{
						name: '月统计',
						type: 2
					}
				],
				selectIndex: 0,
				mescroll: null,
				total: '0'
			};
		},
		mixins: [globalConfig],
		onLoad(option) {

		},
		onShow() {
			this.$langConfig.refresh();
			this.$langConfig.title('业绩统计');
			this.getTeamPerformance();
		},
		methods: {
			selectEvent(index) {
				if (this.selectIndex != index) {
					this.selectIndex = index;
					this.mescroll.resetUpScroll();
				}
			},
			getTeamPerformance() {
				this.$api.sendRequest({
					url: '/fenxiao/api/order/getTeamPerformance',
					success: res => {
						if (res.code == 0) {
							this.total = res.data.total;
						}
					}
				})
			},
			//获得列表数据
			getData(mescroll) {
				this.mescroll = mescroll;
				this.emptyShow = false;
				if (mescroll.num == 1) {
					this.orderList = [];
				}
				this.$api.sendRequest({
					url: '/fenxiao/api/order/getTeamPerformanceDetail',
					data: {
						page: mescroll.num,
						page_size: mescroll.size,
						type: this.menus[this.selectIndex].type
					},
					success: res => {
						this.emptyShow = true;
						let newArr = [];
						let msg = res.message;
						if (res.code == 0 && res.data && res.data.list) {
							newArr = res.data.list;
						} else {
							
						}
						mescroll.endSuccess(newArr.length);
						//设置列表数据
						if (mescroll.num == 1) this.orderList = []; //如果是第一页需手动制空列表
						this.orderList = this.orderList.concat(newArr); //追加新数据
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					},
					fail: res => {
						mescroll.endErr();
						if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
					}
				});
			}
		}
	};
</script>

<style lang="scss">
	.head-box {
		.part-one {
			width: 100vw;
			height: 176rpx;
			background-color: #FFF3F1;
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;

			.team-all {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #222222;
				line-height: 33rpx;
			}

			.team-num {
				margin-top: 8rpx;
				font-family: Helvetica, Helvetica;
				font-weight: bold;
				font-size: 56rpx;
				color: #FC311A;
				line-height: 66rpx;
			}
		}

		.part-two {
			width: 100vw;
			height: 98rpx;
			background-color: #fff;
			display: flex;

			.menu-item {
				flex: 1;
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #999999;
				line-height: 50rpx;

				&.native {
					font-family: PingFang SC, PingFang SC;
					font-weight: 500;
					font-size: 34rpx;
					color: #FC311A;
					line-height: 50rpx;
					position: relative;

					&::after {
						content: '';
						display: block;
						width: 25%;
						height: 4rpx;
						background-color: #FC311A;
						border-radius: 2rpx;
						position: absolute;
						bottom: 0;
						left: 38%;
					}
				}
			}
		}
	}

	.order-list {
		padding: 20rpx 24rpx 0 24rpx;

		.order-item {
			border-radius: 16rpx;
			background-color: #fff;
			margin-bottom: 20rpx;

			.item-type-one {
				padding: 28rpx 28rpx 26rpx 18rpx;
				display: flex;

				.img-box {
					min-width: 48rpx;
					max-width: 48rpx;
					height: 48rpx;
					border-radius: 50%;
				}

				.c-box {
					margin-left: 18rpx;
					width: 100%;

					.c-o-box {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.name-label {
							font-family: PingFang SC, PingFang SC;
							font-weight: 500;
							font-size: 32rpx;
							color: #222222;
							line-height: 38rpx;
						}

						.num-label {
							font-family: Helvetica, Helvetica;
							font-weight: bold;
							font-size: 34rpx;
							color: #222222;
							line-height: 40rpx;
						}
					}

					.dec-label {
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #999999;
						line-height: 30rpx;
						margin-top: 16rpx;
					}
				}
			}

			.item-type-two {
				padding: 30rpx 24rpx 26rpx 28rpx;

				.p-one-box {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.date-label {
						ont-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 32rpx;
						color: #222222;
						line-height: 38rpx;
					}

					.num-label {
						font-family: Helvetica, Helvetica;
						font-weight: bold;
						font-size: 34rpx;
						color: #222222;
						line-height: 40rpx;
					}
				}

				.time-box {
					margin-top: 16rpx;
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #999999;
					line-height: 30rpx;
				}
			}
		}
	}
</style>